const path = require('path')
const assert = require('assert')
const defaultOptions = {
  entry: {
    defaultValue: path.resolve(process.cwd(), `./src/electron/index.js`),
    type: 'string'
  },
  output: {
    defaultValue: path.resolve(process.cwd(), `./electron-dist`),
    type: 'string'
  }
}
module.exports = (options = {}) => {
  assert(typeof options === 'object', '配置必须是一个对象')
  const defaultKeys = Object.keys(defaultOptions)
  return defaultKeys.reduce((container, key) => {
    if (options[key] && typeof options[key] === defaultOptions[key].type) {
      if (path.isAbsolute(options[key])) {
        return { ...container, [key]: options[key] }
      }
      return { ...container, [key]: path.resolve(process.cwd(), options[key]) }
    }
    return { ...container, [key]: defaultOptions[key].defaultValue }
  }, {})
}
